@{
    ViewBag.Title = "运行HQL";
}
@section head{
   <script type="text/javascript">
       function smt(type) {
           $('form').attr('action', '?type=' + type).submit();
       }
   </script>
}
@section body{
<body style="padding:@ViewBag.Padding">
<form method="post">
    <div>
        请在此处输入HQL语句：
    </div>
   <textarea name="Hql" class="easyui-validatebox" data-options="required:true"  style=" width:100%; height:300px; margin-top:10px;" >@ViewBag.Hql</textarea>
   <div style=" margin-top:10px; text-align:center; ">
      <input type="button" value="执行查询" class="btnSubmit" onclick="smt('query')" />
      <input type="button" value="单个结果" class="btnSubmit" onclick="smt('single')" />
      <input type="button" value="执行命令" class="btnSubmit" onclick="smt('command')"/>
   </div>
   <div class="hr"></div>
   @if(IsPost)
   {
       if (string.IsNullOrEmpty(ViewBag.Message))
       {
       <table class="easyui-datagrid" id="details" data-options="fit:true,rownumbers:true,singleSelect:false,border:true">
           <thead>
              <tr>
              @{var pers = ViewBag.Data[0].GetType().GetProperties(); }
              @foreach (var i in pers)
              {
                  <th data-options="field:'@i.Name'">@i.Name</th>
              }
              </tr>
           </thead>
           <tbody>
              @foreach (var i in ViewBag.Data)
              {
                  <tr>
                      @foreach (var p in pers)
                      {
                          try
                          {
                          <td>@p.GetValue(i, null)</td>
                          }catch(Exception e){}
                      }
                  </tr>
              }
           </tbody>
       </table>
       }
       else
       {
          <div>@ViewBag.Message</div>
       }           
   }
</form>
</body>
}